﻿Friend Class frmRecentConfiguration
    Private ReadOnly m_eProjectType As Helper.ProjectType

    Private Sub pbCancel_Click(sender As Object, e As EventArgs) Handles pbCancel.Click
        Try
            Hide()
        Catch oExp As Exception
            Helper.DisplayException(oExp, Me, "Exception During Save")
        End Try
    End Sub

    Private Sub pbSave_Click(sender As Object, e As EventArgs) Handles pbSave.Click
        Try
            Dim oExtensions As List(Of String) = New List(Of String)(lstExtensions.Items.Count)
            For Each szItem As String In lstExtensions.Items
                oExtensions.Add(szItem.ToUpper())
            Next

            Helper.SaveMaxItemsToStore(m_eProjectType, nudMaxItems.Value)
            Helper.SaveCodeFileExtensions(m_eProjectType, oExtensions)
            Hide()
        Catch oExp As Exception
            Helper.DisplayException(oExp, Me, "Exception During Save")
        End Try
    End Sub

    Public Sub New(eProjectType As Helper.ProjectType)
        m_eProjectType = eProjectType

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        nudMaxItems.Value = Helper.GetMaxItemsToStore(m_eProjectType)
        lstExtensions.Items.AddRange(Helper.GetCodeFileExtensions(m_eProjectType).ToArray())
    End Sub

    Private Sub pbRemove_Click(sender As Object, e As EventArgs) Handles pbRemove.Click
        Try
            For iPos = 0 To lstExtensions.SelectedItems.Count - 1
                Dim szExtension As String = lstExtensions.SelectedItems(0)
                lstExtensions.Items.Remove(szExtension)
            Next
        Catch oExp As Exception
            Helper.DisplayException(oExp, Me, "Exception Removing Selected Extensions")
        End Try
    End Sub

    Private Sub pbAdd_Click(sender As Object, e As EventArgs) Handles pbAdd.Click
        Try
            Dim szNew As String = InputBox("Extension To Add", "New Code File Extension").Trim().ToUpper()

            If (szNew.Length = 0) Then Return

            If (Not lstExtensions.Items.Contains(szNew)) Then
                lstExtensions.Items.Add(szNew)
            End If
        Catch oExp As Exception
            Helper.DisplayException(oExp, Me, "Exception Adding New Extension")
        End Try
    End Sub
End Class